<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Images extends MY_Controller {
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function candidate($candidate_id = null, $candidate_name = null)
	{
		$this->lang->load('candidate/profile', $this->session->userdata['user_lang']);
		$this->lang->load('candidate/images', $this->session->userdata['user_lang']);
		$this->lang->load('candidate/galery', $this->session->userdata['user_lang']);
		$this->load->model('Candidate_model', 'candidate');
		$this->load->helper('date');
		
		$this->get_subscription_menu($data, null, $candidate_id);
		
		$data['main_content'] = 'candidate/profile/galery';
        $data['userdata'] = $this->session->userdata;
        
        $data['candidate'] = $this->candidate->get_complete_profile(array('idcandidate' => $candidate_id));
        $data['profile_image'] = $data['candidate']->image;
        
        $data['grid_galery'] = $this->get_candidate_galery($data['candidate']->idmember);
		
        $data['page_title'] = sprintf($this->lang->line('images_profilegalery'), $data['candidate']->firstname . ' ' . $data['candidate']->lastname);
        $this->load->view('template-candidate-profile', $data);
	}
	
	private function get_candidate_galery($member_id)
	{
		$this->lang->load('candidate/galery', $this->session->userdata['user_lang']);
		$this->load->model('Candidate_galery_model', 'galery');
		
		$images_list = $this->galery->get(array('idmember' => $member_id));
		
		$grid_images = array();
        
		foreach ($images_list->result() as $row)
		{
			$grid_images[] = '<div class="row"><span><span class="img-galery"><span class="img-border fleft vmiddle">
			<a href="'.base_url() . "f/" . $member_id . '/img/' . $row->image.'" rel="facebox">
			<img class="pointer" src="'.base_url() . "f/" . $member_id . '/img/' . $row->thumbnail.'" /></a></span></span>
			<span class="fleft vmiddle box-description"><h3>'.$row->title.'</h3><p>'.nl2br($row->description).'</p></span>
			</span>
			<div class="gtool">
				<a href="'.base_url() . "f/" . $member_id . '/img/' . $row->image.'" rel="facebox">'.$this->lang->line('galery_viewphoto').'</a>
			</div></div>';
		}
		
		if (!$grid_images) {
			 return '<center>'.$this->lang->line('galery_noresults').'</center>';
		} else {
			 return implode('<hr/>', $grid_images);
		}
	}
	
	public function company($company_id = null, $company_name = null)
	{
		$this->lang->load('company/profile', $this->session->userdata['user_lang']);
		$this->lang->load('company/images', $this->session->userdata['user_lang']);
		$this->lang->load('company/galery', $this->session->userdata['user_lang']);
		$this->load->model('Company_model', 'company');
		$this->load->helper('date');
	
		//$this->get_subscription_menu($data, null, $candidate_id);
	
		$data['main_content'] = 'company/profile/galery';
		$data['userdata'] = $this->session->userdata;
	
		$data['company'] = $this->company->get_complete_profile(array('idcompany' => $company_id));
		$data['profile_image'] = $data['company']->image;
	
		$data['grid_galery'] = $this->get_company_galery($data['company']->idmember);
	
		$data['page_title'] = sprintf($this->lang->line('images_profilegalery'), $data['company']->name);
		$this->load->view('template-company-profile', $data);
	}
	
	private function get_company_galery($member_id)
	{
		$this->lang->load('company/galery', $this->session->userdata['user_lang']);
		$this->load->model('Company_galery_model', 'galery');
	
		$images_list = $this->galery->get(array('idmember' => $member_id));
	
		$grid_images = array();
	
		foreach ($images_list->result() as $row)
		{
			$grid_images[] = '<div class="row"><span><span class="img-galery"><span class="img-border fleft vmiddle">
			<a href="'.base_url() . "f/" . $member_id . '/img/' . $row->image.'" rel="facebox">
			<img class="pointer" src="'.base_url() . "f/" . $member_id . '/img/' . $row->thumbnail.'" /></a></span></span>
			<span class="fleft vmiddle box-description"><h3>'.$row->title.'</h3><p>'.nl2br($row->description).'</p></span>
			</span>
			<div class="gtool">
			<a href="'.base_url() . "f/" . $member_id . '/img/' . $row->image.'" rel="facebox">'.$this->lang->line('galery_viewphoto').'</a>
			</div></div>';
		}
	
		if (!$grid_images) {
			return '<center>'.$this->lang->line('galery_noresults').'</center>';
		} else {
			return implode('<hr/>', $grid_images);
		}
	}
}

?>